﻿using System;
using System.Web.UI.WebControls;
using ContractManagementSystem.BusinessLogic;
using ContractManagementSystem.Entity;

namespace ContractManagementSystem
{
    public partial class PageReportConsultant : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewConsultantPanel.Visible = true;
                SearchConsultant();
            }
        }

        public void SearchConsultant()
        {
            if (!string.IsNullOrEmpty(FullNameTextBoxSearch.Text))
            {
                ViewAllConsultantListView.DataSource = ConsultantBusiness.SearchFullName(FullNameTextBoxSearch.Text);
                ViewAllConsultantListView.DataBind();
                Session["ReportConsultant"] = ConsultantBusiness.SearchFullName(FullNameTextBoxSearch.Text);
            }
            else
            {
                ViewAllConsultantListView.DataSource = ConsultantBusiness.FetchAll(ActiveDropDownList.SelectedIndex);
                ViewAllConsultantListView.DataBind();
                Session["ReportConsultant"] = ConsultantBusiness.FetchAll(ActiveDropDownList.SelectedIndex);
            }

        }

        protected void FullNameTextBoxTextChanged(object sender, EventArgs e)
        {
            SearchConsultant();
        }

        protected void ActiveDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            SearchConsultant();
        }

        protected void DataPager1_OnPreRender(object sender, EventArgs e)
        {
            SearchConsultant();
        }

        protected void DeleteButton_OnCommand(object sender, CommandEventArgs e)
        {
            var consultantEntity = new ConsultantEntity { ConsultantId = new Guid(e.CommandArgument.ToString()) };
            ConsultantBusiness.Delete(consultantEntity);
            SearchConsultant();
        }

        protected void ReportButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ReportConsultant.aspx");
        }
    }
}
